package com.njit.mailm.core.service.impl;

import com.njit.mailm.core.bean.Classify;
import com.njit.mailm.core.bean.Email;
import com.njit.mailm.core.bean.MessageWrap;
import com.njit.mailm.core.bean.User;
import com.njit.mailm.core.dao.ClassifyDao;
import com.njit.mailm.core.dao.MailDao;
import com.njit.mailm.core.service.ClassifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.core.ClassInfo;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2016/5/10.
 */
@Service
public class ClassifyServiceImpl implements ClassifyService {
    @Autowired
    private ClassifyDao classifyDao;

    @Autowired
    private MailDao mailDao;
    public List<MessageWrap> getAllUnreadMessage(String userid) {
        List<Email> emails = classifyDao.getAllEmailByUserId(userid);
        return classifyDao.getAllUnreadMessage(emails);
    }

    public MessageWrap getMessageById(String id) {
        return classifyDao.getMessageById(id);
    }

    public List<MessageWrap> getAllStarMessage(String id) {

        return classifyDao.getAllStarMessage(id);
    }

    public List<MessageWrap> showAllMessage(String id) {
        return  classifyDao.showAllMessage(id);
    }

    public boolean addMessage(String name,String messageId, User user) {
        try {
            Classify classify = classifyDao.getClassifyByName(name, user);
            MessageWrap message = mailDao.selectMessageById(messageId);
            classifyDao.addMessage2Classify(classify,message);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

    public List<MessageWrap> showMessageInClassify(String classify, User user) {
        Classify classify1 = classifyDao.getClassifyByName(classify, user);
        return classifyDao.getMessageInClassify(classify1);
    }
}
